package com.fh.service.ServiceCheck;

import com.fh.exception.ServiceException;
import com.fh.service.airsys.airlineemployee.AirlineEmployeeService;
import com.fh.util.PageData;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 账户余额查询
 * Created by tugou on 2017/9/24.
 */
@Component("accBalanceCheck")
public class AccBalanceCheck extends CheckHandler {

    @Autowired
    AirlineEmployeeService airlineEmployeeService;

    protected void handle(PageData data) throws ServiceException, Exception {
        PageData pd = airlineEmployeeService.findById(data);
        if(pd == null){
            throw new ServiceException(50002,"查询不到用户信息或者改用户状态为不可用");
        }
        else{
            Long balance = Long.valueOf((String) pd.get("SA_BALANCE"));
            Long tranAmt = Long.valueOf((String) data.get("tranAmt"));
            if(balance < tranAmt){
                throw new ServiceException(50003,"当前余额不足");
            }
        }
    }
}
